<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<button id="connect">连接</button>
<button id="send">发送数据</button>
<span id="recv"></span>
<script>
  let connect = document.querySelector('#connect')
  let send = document.querySelector('#send')
  let recv = document.querySelector('#recv')
  let ws
  connect.onclick = function () {
    ws = new WebSocket('ws://localhost:9998')
    ws.onopen = () => {
      alert('连接成功')
    }
    ws.onclose = () => {
      alert('连接失败')
    }
    ws.onmessage = (msg) => {
      console.log(msg)
      recv.innerHTML = msg.data
    }
  }

  send.onclick = function () {
    let s = JSON.stringify({
      action: 'l',
      socketType: 'fullScreen',
      chartName: 'trend',
      value: true
    });
    console.log(s)
    ws.send(s)
  }
</script>
</body>
</html>